<template>
  <view class="track-button" @click="onTrack">
    <slot></slot>
  </view>
</template>

<script setup lang="ts">
import type { TrackData } from './TrackTypes'
import { TrackType, trackEvent } from '../tracks'
import { safeTrack } from '../dataReportUtil'
const props = defineProps<{
  type?: TrackType
  trackId: string
  trackData?: TrackData
  buttonId?: string // 埋点key trackId
}>()

const emit = defineEmits<{
  (e: 'click', event: WechatMiniprogram.TouchEvent): void
}>()

function onTrack(event: MouseEvent) {
  safeTrack(() => {
    trackEvent(
      props.trackId,
      props.trackData,
      props.type ? props.type : TrackType.BusinesssScene,
      props.buttonId ? props.buttonId : null
    )
  })

  emit('click', event as unknown as WechatMiniprogram.TouchEvent)
}
</script>

<style lang="less">
track-button,
.track-button {
  display: contents;
}
</style>
